<template>
  <div class="my-tag" @dblclick="clickFn">
    <input
      v-focus
      v-if="is"
      class="input"
      type="text"
      v-model='tag'
      @blur='close'
      placeholder="输入标签"
      @keydown.enter="close"
    />
    <div v-else class="text">{{ value }}</div>
  </div>
</template>

<script>
export default {
  props: ['value'],
  data() {
    return {
      is: false,
      tag: ''
    }
  },
  methods: {
    clickFn() {
      this.is = true
      this.tag = this.value
    },
    close() {
      this.is = false
      this.$emit('input', this.tag)
    }
  },
}
</script>

<style lang="less" scope>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>
